// 控制器
const connection = require('../data');
// 顶部轮播图
module.exports.showTop = (req, res) => {
    connection.query('select * from top_carousel', (err, data) => {
        if (err) return console.log(err);
        res.json({
            code: "1001",
            data: data
        })
    })
}
//中间的上下轮播图
module.exports.idxShowJmys = (req, res) => {
    connection.query('select * from well_carousel order BY image_location', (err, data) => {
        if (err) return console.log(err);
        let arr = [];
        let num = 1;
        let newArr = [];
        for (let i = 0; i < 3; i++) {
            data.forEach(element => {
                if (element.image_location == num) {
                    newArr.push(element)
                }
            });
            arr.push(newArr)
            newArr = [];
            num++;
        }
        res.json(arr)
    })
}
// 店铺展示
module.exports.idxShowShop = (req,res)=>{
    connection.query('select * from  show_carousel',(err,data)=>{
        if(err)  return console.log(err);    
        res.json({
            code:'1003',
            data:data
        })
    })
}

module.exports.idxShowNewsTitle = (req,res)=>{
    let sql = "select n.id,n.title,FROM_UNIXTIME(n.created_at , '%Y-%m-%d') time from page_news n  where  n.page_options_id = (select id from page_options where `option` = '公司动态') limit 0,6";
    connection.query(sql,(err,data)=>{
        if(err) return console.log(err);
        res.json(data)
    })
}

module.exports.idxShowNewsTrade = (req,res)=>{
    let sql = "select n.id,n.title,FROM_UNIXTIME(n.created_at , '%Y-%m-%d') time from page_news n  where  n.page_options_id = (select id from page_options where `option` = '行业资讯') limit 0,6";
    connection.query(sql,(err,data)=>{
        if(err) return console.log(err);
        res.json(data)
    })
}